package com.oocl.homework.format.data;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

import com.oocl.homework.exception.VerifyException;
import com.oocl.homework.format.moel.Customer;
import com.oocl.homework.format.moel.CustomerFactory;
import com.oocl.homework.verify.MyVerify;
import com.oocl.homework.verify.Verifyable;

public class DataLoad implements DataLoadable{
	
	
	
	

	public void load(Scanner scanner) {
		CustomerDao customerDao = CustomerDaoImpl.getInstance();
		Map<String,String> map = new HashMap<>();
		Verifyable verifyable = new MyVerify();
		while (scanner.hasNextLine()) {
			String[] str = scanner.nextLine().trim().split("[\\s]+");
			if (str.length<5) {
				continue;
			}
			map.put("id", str[0]);
			map.put("name", str[1]);
			map.put("email", str[2]);
			map.put("sex", str[3]);
			map.put("birthday", str[4]);
			try {
				Customer customer = CustomerFactory.getInstanceWithVerify(map, verifyable);
				customerDao.add(customer);
				
				
			} catch (VerifyException e) {
				// log here
				e.printStackTrace();
			}
		}
	}
	
	
	
	
	public Set<Customer> getCustomers1() {
		return CustomerDaoImpl.getInstance().getCustomers();
	}



	public Set<Customer> getCustomers2() {
		return CustomerDaoImpl.getInstance().getCustomersSortByBirthday();
	}



	
	
	

}
